package org.ring.common.transport;

/**
 *
 * len
 * 2
 *
 * 2 + 4 + (n byte)
 *
 * @since 2023-10-27 11:27
 */
public class Message {

    private long id;
    private int len;
    //1 byte  0 ，1， 2， 4
    private int flag;

    private Object data;

    public static final int REQUEST = 0x01;
    public static final int RESPONSE = 0x03;

    public Message() {

    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public int getLen() {
        return len;
    }

    public void setLen(int len) {
        this.len = len;
    }

    public int getFlag() {
        return flag;
    }

    public void setFlag(int flag) {
        this.flag = flag;
    }

    public boolean isRequest(){
        return (this.flag & REQUEST) == 0;
    }

    public void markResponse(){
        this.flag |= REQUEST;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public Object getData() {
        return data;
    }

    @Override
    public String toString() {
        return "Message{" + "id=" + id + ", len=" + len + ", flag=" + flag + ", data=" + data + '}';
    }
}
